// import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'

import Thematic from '@/router/back/Thematic'
import Class from '@/router/back/Class'
import Exam from '@/router/back/Exam'
import Meeting from '@/router/back/Meeting'
import Questions from '@/router/back/Questions'
import User from '@/router/back/User'
import backMeeting from './huang/backMeeting'
import front from "@/router/he/front"
import TeachersDetail from "@/router/Pu/TeachersDetail"
import CommentMenu from "@/router/hu/CommentMenu"
import ManageDetail from "@/router/hu/ManageDetail"
import test2 from "@/router/hu/test"
import my from "@/router/my/my"





const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'login',
      component: () => import('../views/login/Login.vue')
    },
    // {
    //   path: '/login1',
    //   name: 'login',
    //   component: () => import('../views/login/Login.vue')
    // },
    {
        path:"/Front",
        name:"Front",
        component:()=>import("@/views/front/Front.vue"),
        children:[
           {
        path:"/FrontMain",
        name:"FrontMain",
        component:()=>import("@/views/front/FrontMain.vue")

          },
           {
        path:"/FrontMeet",
        name:"FrontMeet",
        component:()=>import("@/views/Meeting Details/Meeting Details.vue")

          },
          ...front,
          ...backMeeting,
          ...TeachersDetail,
          ...CommentMenu,
          ...ManageDetail,
          ...test2,
          ...my,
          ...CommentMenu

        ]

    },
    {
      path: '/BackMain',
      name: 'BackMain',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/back/BackMain.vue'),
      children:[
       {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
      },
        ...Thematic,
        ...User,
        ...Class,
        ...Exam,
        ...Questions,
        ...Meeting,
        ...backMeeting
      ]
    },
    
    
  
    // ...ManageDetail


  ]
})

router.beforeEach((to:any,from:any,next:any)=>{
  if(to.path=="/"){    
    next();
  }else{
   
    
    
     if(localStorage.getItem("token")==null){
      next("/");
    }
    else (localStorage.getItem("token")!=="")
    
    {
      //  console.log(localStorage.getItem("token"));
      
      next();
    }
  }
  
})

export default router
